package com.dlc.felear.xiaoensale.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.adapter.ActionItemStepAdapter;
import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.customView.LoadingDialog;
import com.dlc.felear.xiaoensale.deviceUtil.TopbarHelper;
import com.dlc.felear.xiaoensale.entity.ActionStepItem;
import com.dlc.felear.xiaoensale.helper.LoadDataHelper;
import com.itdlc.android.library.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 数据下载页面
 */
public class LoadDataActivity extends BaseActivity {
    private static final String TAG = "LoadDataActivity";
    private static final String GLSCSJ = "管理食材数据";
    private static final String CPBDICK = "菜谱绑定IC卡";
    private static final String CPUPD = "管理菜谱";
    private static final String CKCCJL = "查看炒菜记录";
    private static final String CPFZ = "菜谱复制";
    private static final String MRTLSZ = "菜谱分类模板设置";
    private static final String XLSDSZ = "下料速度设置";
    private static final String CPTPGL = "菜谱图片管理";
    private TopbarHelper topbarHelper;
    @BindView(R.id.cp_gv1)
    GridView gridView;
    private LoadingDialog loadingDialog;
    private ActionItemStepAdapter actionItemStepAdapter;
    private LoadDataHelper loadDataHelper;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_update_base_data;
    }

    @Override
    protected void initialView() {
        loadDataHelper =  LoadDataHelper.getInstance(this);
        topbarHelper = new TopbarHelper(this);
        topbarHelper.setTitle("菜谱数据管理");
        topbarHelper.setcon(R.drawable.arrow_left);
        topbarHelper.setNavActivity(ParamerSettingActivity.class);
        loadingDialog = new LoadingDialog(this, "正在执行..");
        actionItemStepAdapter = new ActionItemStepAdapter(this);
        gridView.setAdapter(actionItemStepAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                handleAction(actionItemStepAdapter.getItem(position).getName());
            }
        });
    }

    @Override
    protected void initData() {
        actionItemStepAdapter.setItems(getActionStepItemData5());
    }

    private void handleAction(String name) {
        switch (name) {
            case GLSCSJ:
                startActivity(new Intent(this, ManagerFoodMatActivity.class));
                break;
            case CPBDICK:
                break;
            case CPUPD:
                startActivity(new Intent(this, EmnuControlActivity.class));
                break;
            case CKCCJL:
                startActivity(new Intent(this, MenuRecordInfoActivity.class));
                break;
            case CPFZ:
//                startActivity(new Intent(this, CopyMenuActivity.class));
                break;
            case XLSDSZ:
                startActivity(new Intent(this, FlavourParamerSettingActivity.class));
                break;
            case MRTLSZ:
                Intent intent=new Intent(this, MenuCategoryListActivity.class);
                intent.putExtra("src",0);
                startActivity(intent);
                break;
            case CPTPGL:
                startActivity(new Intent(this, MenuPicDataActivity.class));
                break;
        }
    }


    private void showDialog() {
        loadingDialog.show("正在下载...");
    }

    private void closeDialog() {
        loadingDialog.close();
    }

    public static List<ActionStepItem> getActionStepItemData5(){
        List<ActionStepItem> list=new ArrayList<>();
        list.add(new ActionStepItem(Constant.ACTION_STEP_JGT,GLSCSJ, R.drawable.setting_1_icon,0));
        list.add(new ActionStepItem(Constant.ACTION_STEP_JGT,CPUPD, R.drawable.setting_1_icon,0));
        list.add(new ActionStepItem(Constant.ACTION_STEP_JGT,XLSDSZ, R.drawable.setting_1_icon,0));
        list.add(new ActionStepItem(Constant.ACTION_STEP_JGT, CPTPGL, R.drawable.setting_1_icon, 0));
        return list;
    }


}